package triangleWorm;

import processing.core.PApplet;
import processing.core.PVector;

public class SinusMovement implements IWormMovement {
	private PVector wSize;
	private PVector wCenter;
	
	//
	private PVector position;
	
	//Noise seeds
	private double  xSinusPosition = 0;
	private double  ySinusPosition = 0;
	private double  zSinusPosition = 0;
	
	//Noise offsets
	private double xOff = 0;
	private double yOff = 0;
	private double zOff = 0;
	
	//Sinus iteration scale
	private double minScale = 0.002;
	private double maxScale= 0.01;
	private final double XSCALE = minScale + Math.random() * (maxScale - minScale);
	private final double YSCALE = minScale + Math.random() * (maxScale - minScale);
	private final double ZSCALE = minScale + Math.random() * (maxScale - minScale);
	
	public SinusMovement() {
		//Initiate position to (0, 0, 0)
		position = new PVector();
	}
	
	
	public void init(PApplet processing, PVector worldSize, PVector worldCenter) {
		wSize = worldSize;
		wCenter = worldCenter;
		
		//Set position to center of world
		position.set(worldCenter.x, worldCenter.y, worldCenter.z);
	}

	public void update() {
		/*
		System.out.println("SIZE: " + wSize.toString());
		System.out.println("CENTER: " + wCenter.toString());
		*/
		
		//Get X value
		//Get noise
		double xSinusValue = Math.sin(xSinusPosition + xOff);
		//Calculate new position in world, world center +/- half world size
		float xPosition = wCenter.x + (wSize.x * (float) xSinusValue) / 2f;
		
		//Get Y value
		double ySinusValue = Math.sin(ySinusPosition + yOff);
		float yPosition = wCenter.y + (wSize.y * (float) ySinusValue) / 2f;

		//Get Z value
		double zSinusValue = Math.sin(zSinusPosition + zOff);
		float zPosition = wCenter.z + (wSize.z * (float) zSinusValue) / 2f;
		
		//Set position
		position.set(xPosition, yPosition, zPosition);
		
		//update noise offsets
		xOff += XSCALE;
		yOff += YSCALE;
		zOff += ZSCALE;

		/*
		System.out.println("POSITION: " + position.toString());
		System.out.println();
		*/
	}

	public PVector getPosition() {
		return position;
	}

}